package com.cs2.volunteerpostbackend.service.impl;

import com.cs2.volunteerpostbackend.service.ContentCheckService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 内容检查服务实现类
 */
@Service
public class ContentCheckServiceImpl implements ContentCheckService {
    
    @Autowired
    @Qualifier("wordsClient")
    private ChatClient chatClient;
    
    @Override
    public boolean containsSensitiveContent(String content) {
        try {
            String result = chatClient.prompt()
                    .user(content)
                    .call()
                    .content();
            return Objects.equals(result, "包含");
        } catch (org.springframework.ai.retry.NonTransientAiException e) {
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}